package com.jh.user.controller.model;

import com.google.common.collect.BoundType;
import com.google.common.collect.Range;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Yichuan
 * @version 1.0
 */
public class RangeRateModel {

    public static RangeRateModel range(Range<BigDecimal> range, BigDecimal rage) {
        RangeRateModel model = new RangeRateModel();
        BigDecimal lower = range.lowerEndpoint(), upper = range.upperEndpoint();
        if (lower != null && range.hasLowerBound()) {
            model.setLower(lower);
            model.setLowerClosed(range.lowerBoundType() == BoundType.CLOSED);
        }
        if (upper != null && range.hasUpperBound()) {
            model.setUpper(upper);
            model.setUpperClosed(range.upperBoundType() == BoundType.CLOSED);
        }
        model.setRate(rage);
        return model;
    }

    private BigDecimal lower;
    private Boolean lowerClosed;
    private BigDecimal upper;
    private Boolean upperClosed;
    private BigDecimal rate;
    //代理商费率
    private BigDecimal agentRate;
    //平台费率
    private BigDecimal platformRate;

    public RangeRateModel() {
    }

    public BigDecimal getAgentRate() {
        return agentRate;
    }

    public void setAgentRate(BigDecimal agentRate) {
        this.agentRate = agentRate;
    }

    public BigDecimal getPlatformRate() {
        return platformRate;
    }

    public void setPlatformRate(BigDecimal platformRate) {
        this.platformRate = platformRate;
    }

    public BigDecimal getLower() {
        return lower;
    }

    public void setLower(BigDecimal lower) {
        this.lower = lower;
    }

    public Boolean getLowerClosed() {
        return lowerClosed;
    }

    public void setLowerClosed(Boolean lowerClosed) {
        this.lowerClosed = lowerClosed;
    }

    public BigDecimal getUpper() {
        return upper;
    }

    public void setUpper(BigDecimal upper) {
        this.upper = upper;
    }

    public Boolean getUpperClosed() {
        return upperClosed;
    }

    public void setUpperClosed(Boolean upperClosed) {
        this.upperClosed = upperClosed;
    }

    public BigDecimal getRate() {
        return rate;
    }

    public void setRate(BigDecimal rate) {
        this.rate = rate;
    }

    public Range<BigDecimal> ofRange() {
        if (getLower() == null && getUpper() == null) {
            return null;
        }
        if (getLower() != null && getUpper() != null) {
            if (getLowerClosed() && getUpperClosed()) {
                return Range.closed(getLower(), getUpper());
            } else if (getLowerClosed()) {
                return Range.closedOpen(getLower(), getUpper());
            } else {
                return Range.openClosed(getLower(), getUpper());
            }
        } else if (getLower() == null) {
            return getUpperClosed() ? Range.closed(BigDecimal.ZERO, getUpper()): Range.closedOpen(BigDecimal.ZERO, getUpper());
        } else {
            return getLowerClosed() ? Range.atLeast(getLower()) : Range.greaterThan(getLower());
        }
    }


}
